﻿using System;
using System.Collections.Generic;
using GameFramework.skill.effect;
using GameFramework.skill.effect.impl;
using GameFramework.skill.selector;
using GameFramework.skill.selector.impl;
using UnityEngine;


namespace GameFramework.skill
{
    [Serializable]
    public class Skill
    {
        public int skillId;
        //技能的静态配置
        public SkillConfig skillConfig;
        //技能释放的目标点
        public List<Vector3> targetPos = new List<Vector3>();
        //技能作用对象数组
        public List<Transform> targets = new List<Transform>();
        
        //上次释放的时间
        public long lastReleasTime;

        //技能释放者
        public GameObject owner;


        public ISkillSelector selector;
        public List<ISkillEffect> effects = new List<ISkillEffect>();


        public void init(int id,GameObject releaser)
        {
            skillId = id;
            owner = releaser;
            //配置从配置管理器中获取
            skillConfig = SkillConfigManager.Instance.getConfig(id);
            //TODO 释放技能是被动的，则看下是否要加buff给玩家
            if (skillConfig.releaseType == 1)
            {
                    
            }
            initSelector();
            initEffects();
        }

        private void initEffects()
        {
            int[] effectIds = skillConfig.effectIds;
            foreach (int effectId in effectIds)
            {
                EffectConfig effectConfig = EffectConfigManager.Instance.getConfig(effectId);
                //TODO 做脚本映射？
                if (effectConfig.type == 1)//直接伤害
                {
                    DamigeHpSkillEffect effect = new DamigeHpSkillEffect();
                    effect.effectConfig = effectConfig;
                    effects.Add(effect);
                }
                if (effectConfig.type == 2)//召唤
                {
                    Debug.LogWarning("召唤效果未实现！");
                }
                if (effectConfig.type == 3)//加buff
                {
                    Debug.LogWarning("加buff效果未实现！");
                }
                if (effectConfig.type == 4)//子弹
                {
                    BulletSkillEffect effect = new BulletSkillEffect();
                    effect.effectConfig = effectConfig;
                    effects.Add(effect);
                }
            }
        }

        private void initSelector()
        {
            //TODO 最好类型id和脚本类型进行映射，后续通过反射创建，就不用改代码了
            if (skillConfig.targetType == 2)
            {
                selector = new SelectTargetSkillSelector();
            }
            if (skillConfig.targetType == 3)
            {
                selector = new SelectTargetSkillSelector();
            }
        }
    }
}